package com.erp.myAdapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.LinearLayout
import com.erp.R
import com.erp.bean.MainItemBeans
import com.erp.util.Myutil
import com.erp.util.Sputil
import kotlinx.android.synthetic.main.main_iv_item.view.iv_item
import kotlinx.android.synthetic.main.main_iv_item.view.tv_item

class MainItemAdapter(private var mlist: MutableList<MainItemBeans.MainItemBean>, private val mcontext: Context) : BaseAdapter() {


    private val minflater: LayoutInflater = LayoutInflater.from(mcontext)
    private var isadd = false
    internal var width = 0

    init {
        width = Sputil.sp("erp").getInt("width", width)
    }

    override fun getCount(): Int = mlist.size

    override fun getItem(position: Int): Any = mlist[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v : View = minflater.inflate(R.layout.main_iv_item, null)
        val iv = v.iv_item
        val tv = v.tv_item
        val params = iv.layoutParams
        params.height = width / 4
        iv.layoutParams = params
        val bean = mlist[position]
        iv.setImageResource(bean.imgId)
        tv.text = bean.title
        return v
    }

    fun isadd(isadd: Boolean) {
        this.isadd = isadd
    }

    fun notifyA(list: MutableList<MainItemBeans.MainItemBean>) {
        this.mlist = list
        notifyDataSetChanged()
    }
}